Skip to content

nvn/mesh: task / mesh pipelines declare 32-thread threadgroups a multiple of the SIMD width (OoT −0.35 ms GPU a frame on an M1) - #2577

Open
AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:mesh-tg-simd-hint
Open

AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:mesh-tg-simd-hint

Conversation

@AdyaGMD

@AdyaGMD AdyaGMD commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What

Task and mesh pipelines (mtk_desc4, and the Metal 3 path) now set objectThreadgroupSizeIsMultipleOfThreadExecutionWidth / meshThreadgroupSizeIsMultipleOfThreadExecutionWidth when the shader's threadgroup is a multiple of 32 threads. NVN2's task and mesh shaders are 32 threads, one SIMD group, so this is always true for them. A mesh shader with no task shader keeps the host's one-thread object function without the hint. The compiler may then drop the code for partial SIMD groups.

DM_NVN_MESH_TGHINT=0 builds them without the hints. The pipeline cache key leaves the flag out, so it can't alternate within a run.

Performance

Ocarina of Time (0400486024DEC000), Kokiri Forest, MacBook M1 (8-core GPU), fullscreen, in a tree with other local changes. The frame is paced at 30 fps, so this measures GPU time: DM_NVN_GPUPROF "first start to last end", frames 1200–2700, two pairs of runs in both orders:

Pair Hint No hint
Hint run second 32.48 ms 32.78 ms
Hint run first 32.34 ms 32.72 ms

About −0.35 ms of GPU time a frame. Requiring the exact sizes as well (requiredThreadsPer...Threadgroup) gave nothing more.

Checked

  • The host compiles on this branch.
  • The offline pipeline archive step (DM_PSO_PREBUILD) runs the host itself, so it builds the same descriptors.

Not run

  • This branch's host in game (it was measured in another tree).
  • Any test suite.
  • iPhone.
  • M3 and later (they have mesh-shading hardware).
  • Other games.

🤖 Generated with Claude Code

…iple of the SIMD width (Ocarina of Time -0.35 ms of GPU time a frame on an M1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 13, 2026
khalilgharbaoui added a commit to khalilgharbaoui/nxnative-ultimate that referenced this pull request Nov 15, 2026
The rows seedds#2577, seedds#2441 and seedds#2574 added went in out of order; test_env_switches compares the table with the sorted output.
@seedds

seedds commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks. The hint is correct: mtk_encode always draws with exactly ts->mesh_threads / ms->mesh_threads, so the flags state something the host guarantees, and the binding (host, from each shader's own size) is the right one. Before landing it, though, it needs a gain we can measure on the PR's own code. On an M4 Pro it shows none.

M4 Pro (20-core GPU), main ae3f169 + this PR, a full library for main's chain, Ocarina at Kokiri Forest (the deck save, standing)

Separate runs were too noisy to decide this: run-to-run spread on one host is up to 0.8 ms here, more than the gain claimed. So I measured within one process. A measurement-only host puts the hint into the mesh pipeline key (the key's spare word), so DM_NVN_MESH_TGHINT=ab DM_AB=300 really alternates the two pipeline variants: the hinted ones were built at the first hint phase and drawn in every hint phase. Each hint phase is compared with the mean of the phases before and after it:

Run Hint phases GPU per frame, hint minus no hint
1 11 +0.09 ms (SE 0.13)
2 9 +0.01 ms (SE 0.07–0.10)

The baseline is about 17.2–17.7 ms of GPU time a frame. So on hardware with mesh shading it is neutral, neither a gain nor a cost.

Can you measure the M1 the same way? Your −0.35 ms came from separate runs in another tree, and that is within the noise we see between runs. For the A/B to work, the hint has to be in the key. The measurement-only change on top of this PR:

  • mesh_tghint split into mesh_tghint_now() (the switch, sw_on) and mesh_tghint_fit(ts, ms, which, on) (the size check).
  • mtk_pso: after mtk_bind_key, k.border_spare = mesh_tghint_now();.
  • mtk_build / mtk_desc4 pass k->border_spare as on.

Then run DM_NVN_MESH_TGHINT=ab DM_AB=300 in a fixed scene and compare the [ab] lines' GPU p50 for MESH_TGHINT phases with their base neighbours, leaving out the first phase in the scene, which builds the pipelines. That change is for measuring only: the key is written into the recorded pipeline rows, so it shouldn't land.

If the M1 shows a consistent gain this way, I'll land the PR (with its docs/env_switches.tsv row moved to its sorted place: appended at the end it fails env_switches.py --check). If not, I'd close it.

@gnavarro24

Copy link
Copy Markdown
Contributor

Hi! This branch is based on a main from before commit c70c242 ("ci: repair host and tool test failures on main"). Most of the failing checks here (Host unit tests, Tool tests, clang-tidy, Build check) come from that older base, not from this change.

To pick up the fix, merge the current main into this branch and push:

git fetch origin
git merge origin/main
git push

If the merge has conflicts, ask here if you want help with them.

@dpadr

dpadr commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Ocarina of Time results on an M2 (MacBook Air, 16 GB, macOS 27), for comparison with the M1 numbers in the description.

Build: our cut9 line (cut9s.2), shader chain f734e024449d, plus this PR and #2868 in the same build. Since both changes were in one build, the effects below can't be attributed to either one alone.

Method: route4 scripted runs, alternating builds (ABAB), scored from frame 600:

  • cap 60, hold off, frame generation off: Kokiri still spot and the walk into the Lost Woods load;
  • cap 30, frame generation on: the walk into the load, plus a back-to-back pair of 8-minute long runs after a fresh reboot.

PWR_ZONE was 0 % in every run.

Results (with both PRs, against the same base without them):

  • Cap 60: frame time the same (−0.2 % mean, still spot +0.1 %, load walk −0.5 %); GPU busy +0.2 % / −0.1 %. The −0.35 ms isn't visible on the M2.
  • Cap 30: GPU busy +1.7 % and +4.4 % mJ a frame (two pairs, same sign). Long-run pair: +3 % GPU cycles a real frame, +5.8 % mJ a real frame, frame-generation slips 4.6 vs 1.1 a minute (one pair).
  • No GPU hangs and no new [RED] lines.

Next step: separate runs of a single build with DM_NVN_MESH_TGHINT=0 vs =1 on a GPU without mesh hardware (M1/M2) would separate this PR's share from #2868's. The note in nvn_geometry.inc says ab can't switch it within a run, because the pipeline cache key leaves it out.

🤖 Generated with Claude Code

@seedds

seedds commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks for the M2 measurements and for calling out that the build included #2868. If you’re able to rerun the comparison, could you try this PR alone on current main in a fixed Kokiri scene at the 60 fps cap with frame generation off? The temporary cache-key change above lets the two settings alternate within one process, where we can measure the hint’s effect on its own. This would give us an M2 result for the hint. The isolated M1 result is still open.

SaranSundar pushed a commit to SaranSundar/nxnative that referenced this pull request Nov 26, 2026
…pulled; seedds#3208 tried

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants